package game;

import utils.Openweb;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class GameFrame extends JFrame {//画布
    GamePanel gamePanel = new GamePanel();
    GameFrame gameFrame = this;

    public GameFrame() {
        super.setSize(600, 300);
        super.setTitle("奔跑吧！恐龙！");//标题
        super.setLocationRelativeTo(null);//居中
        super.add(gamePanel);
        Menu();
        super.setResizable(false);
        this.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                //获得鼠标的位置
                int x = e.getX();
                int y = e.getY();
//                System.out.println(x);
//                System.out.println(y);
                // 97 190
                // 168 231
                // 宽70  高40
                if (x > 127 & x < 169 && y > 210 & y < 260) {
                    GameData.Skin = "normal";
                    GameData.gameoverImg = ImageManager.loadImage("src/Images/" + GameData.Skin + "/gameover.png");
                    GameData.color = new Color(0, 0, 0);//字体颜色
                    gameFrame.setBackground(new Color(247, 247, 247));
                    GameManager.getInstance().gameInit();
                }
                if (x > 198 & x < 239 && y > 210 & y < 260) {
                    GameData.Skin = "black";
                    GameData.gameoverImg = ImageManager.loadImage("src/Images/" + GameData.Skin + "/gameover.png");
                    GameData.color = new Color(0, 0, 0);
                    gameFrame.setBackground(new Color(66, 202, 255));
                    GameManager.getInstance().gameInit();
                }
                if (x > 267 & x < 307 && y > 210 & y < 260) {
                    GameData.Skin = "coloured";
                    GameData.gameoverImg = ImageManager.loadImage("src/Images/" + GameData.Skin + "/gameover.png");
                    GameData.color = new Color(0, 0, 0);
                    gameFrame.setBackground(new Color(175, 132, 132));
                    GameManager.getInstance().gameInit();
                }
                if (x > 337 & x < 376 && y > 210 & y < 260) {
                    GameData.Skin = "batman";
                    GameData.gameoverImg = ImageManager.loadImage("src/Images/" + GameData.Skin + "/gameover.png");
                    GameData.color = new Color(0, 0, 0);
                    gameFrame.setBackground(new Color(89, 97, 108));
                    GameManager.getInstance().gameInit();
                }
                if (x > 408 & x < 449 && y > 210 & y < 260) {
                    GameData.Skin = "mario";
                    GameData.gameoverImg = ImageManager.loadImage("src/Images/" + GameData.Skin + "/gameover.png");
                    GameData.color = new Color(255, 255, 255);
                    gameFrame.setBackground(new Color(0, 0, 0));
                    GameManager.getInstance().gameInit();
                }
            }
        });//鼠标点击事件
        super.setVisible(true);//显示
        super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //idea同步结束程序
    }//设置窗口大小

    public void Menu() {
        JMenuBar menuBar = new JMenuBar();
        setJMenuBar(menuBar);

        JMenu Menu = new JMenu("菜单");
        menuBar.add(Menu);

        JMenuItem list = new JMenuItem("排行榜");
        Menu.add(list);
        list.addActionListener(e -> Openweb.Open());

        JMenuItem exitMenuItem = new JMenuItem("退出");
        Menu.add(exitMenuItem);
        exitMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });


    }


}
